package com.flyweight;

import com.flyweight.factory.ShapeFactory;
import com.flyweight.po.Square;

public class Test {

    private static final String colors[] = { "Red", "Green", "Blue", "White", "Black" };

    public static void main(String[] args) {
        // 共（享）颜色（元）
        for (int i = 0 ; i < 20 ; i++ ) {
            Square square = (Square) ShapeFactory.getSquare(getRandomColor());
            square.setX_axis_length(getRandom());
            square.setY_axis_length(getRandom());
            square.draw();
            // System.out.println(square.hashCode());  // 通过hashCode可知，一共就创建了5个对象
        }
    }

    private static String getRandomColor() {
        return colors[(int)(Math.random()*colors.length)];
    }

    private static int getRandom() {
        return (int)(Math.random()*100 );
    }
}
